package com.lap.framework.generator.shared.enums;

import com.lap.framework.generator.shared.exception.ConfigError;
import java.util.Arrays;
import lombok.Getter;

@Getter
public enum NullType {
  YES("YES", "否"),
  NO("NO", "是"),
  ;

  private final String code;
  private final String labelZh;

  NullType(String code, String labelZh) {
    this.code = code;
    this.labelZh = labelZh;
  }

  public static boolean isNull(String code) {
    return NullType.YES.code.equals(code);
  }

  public static NullType getByValue(String code) {
    return Arrays.stream(NullType.values())
        .filter(nullType -> nullType.code.equalsIgnoreCase(code))
        .findFirst()
        .orElseThrow(() -> new ConfigError("数据库字段类型不正确."));
  }
}
